package com.itmuch.usercenter.rocketmq;

import com.itmuch.usercenter.dao.user.UserMapper;
import com.itmuch.usercenter.domain.dto.messaging.UserAddBonusMsgDTO;
import com.itmuch.usercenter.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
// 会造成重复接收， 均有效
//@Service
//@RocketMQMessageListener(consumerGroup = "binder-group",topic = "add_bonus") //想通组名会yml会报错
@Slf4j
public class AddBonusListener implements RocketMQListener<UserAddBonusMsgDTO> {

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserService userService;

    @Override
    public void onMessage(UserAddBonusMsgDTO userAddBonusMsgDTO) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        userService.addBonus(userAddBonusMsgDTO);
        log.info("触发了Rocketmq Listener");
    }


}
